package org.example.liaoxuefeng.tongyilingma;

/**
 * @author: 默苍璃
 * @date: 2024-07-17 17:31
 */
public class AddCommand implements Command {

    private TextEditor editor;
    private String text;
    private int cursorPosition;


    public AddCommand(TextEditor editor, String text) {
        this.editor = editor;
        this.text = text;
        this.cursorPosition = editor.buffer.length();
    }

    @Override
    public void execute() {
        editor.buffer.append(text);
    }

    @Override
    public void undo() {
        editor.buffer.delete(cursorPosition, cursorPosition + text.length());
    }

}

